
<script>
    layui.use(['upload', 'layer', 'form', 'laydate'], function () {
        var $ = layui.jquery
            , upload = layui.upload
            , form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate;


        
        //普通图片上传
        $(".uploadPic").each(function (index, elem) {
            upload.render({
                elem: $(elem)
                , url: '{{ route("api.upload") }}'
                , multiple: false
                , data: {"_token": "{{ csrf_token() }}"}
                , done: function (res) {
                    //如果上传失败
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1}, function () {
                            $(elem).parent('.layui-upload').find('.layui-upload-box').html('<li><img src="' + res.url + '" /><p>上传成功</p></li>');
                            $(elem).parent('.layui-upload').find('.layui-upload-input').val(res.url);
                        })
                    } else {
                        layer.msg(res.msg, {icon: 2})
                    }
                }
            });
        });

        //多图片上传
        $('.myUpload').each(function (idx, elem) {
            upload.render({
                elem: $(elem)
                , url: '{{ route("api.upload") }}' //此处配置你自己的上传接口即可
                , multiple: true
                , data: {"_token": "{{ csrf_token() }}"}
                , done: function (res) {
                    //上传完毕
                    $(elem).parent('.layui-upload').find('.layui-upload-list').append('<div class="layui-upload-img"><img src="' + res.url + '" alt=""><span><i class="layui-icon">&#x1006;</i></span></div>')
                    var arr = [];
                    $(elem).parent('.layui-upload').find('.layui-upload-img').each(function (i, e) {
                        var str = $(e).find('img').attr('src')
                        if (arr.indexOf(str) == -1) {
                            arr.push(str)
                        }
                    })
                    $(elem).parent('.layui-upload').find('.layui-upload-input').val(JSON.stringify(arr))
                }
            });
        });

        form.on('select(device_type)', function (data) {
            var device_type = data.elem[data.elem.selectedIndex].value;
            if (device_type == 2){
                $(".device_gg").show();
                $(".device_lx").hide();
            }else{
                $(".device_gg").hide();
                $(".device_lx").show();
            }
            form.render('select');
        });


        form.on('submit(formDemo)', function (data) {
            $('.layui-form').submit();
        });

    })
</script>
<script src="/baidu-editor/third-party/jquery.min.js"></script>
